<!-- 线路管理 -->
<template>
<div class="content-box">
  <FilterBox
    :labelWidth="120"
    :filterItemList="filterItemList"
    :filterData="filterData"
    @search="search"
    @clear="clear"
    @keep="keepHeaderList"
  >
  </FilterBox>
  <MyTable
    ref="LineManagement"
    :tableColumn="tableColumn"
    :tableData="tableData"
    @setOrder="setOrder"
    @sendCurrentData="setCurrent"
    @cellDblclick="cellDblclick"
    >
    <template v-slot:content="scope">
      <span class="btnCLass" v-if="scope.config.templateType=='SwitchBtn_examine_type'">
        <el-switch
          @change="switchChange_examine_type(scope.row)"
          v-model="scope.row.examine_type"
          active-color="#26BD00"
          inactive-color="#c0c4cc"
          :active-value='1'
          :inactive-value='0'
          >
        </el-switch>
      </span>
      <span class="btnCLass" v-else-if="scope.config.templateType=='SwitchBtn_status'">
        <el-switch
          @change="switchChange_status(scope.row)"
          v-model="scope.row.status"
          active-color="#26BD00"
          inactive-color="#c0c4cc"
          :active-value='0'
          :inactive-value='1'
          >
        </el-switch>
      </span>
      <span v-else>{{ scope.row[scope.config.prop] }}</span>
    </template>
  </MyTable>
  <!-- 分页组件 -->

  <Pagination
    :currentPage="pageinfo.page"
    :pageSize="pageinfo.limit"
    :total="pageinfo.number_all"
    :page_all="pageinfo.page_all"
    @pagination="SetPagination"
    @sendPushButton="pushButton"
  >
  </Pagination>

  <Add
    @details_next_step="next_step_details"
    @next_step="next_step_add"
    ref="add"
  ></Add>
  <Edit
    @details_next_step="next_step_details"
    @next_step="next_step_edit"
    ref="edit"
  ></Edit>
  <Details
    @next_step="next_step_details"
    ref="details"
  ></Details>
  <Timely
    @next_step="next_step_timely"
    @Previous_step="Previous_step_timely"
    ref="timely"
  ></Timely>
  <Insurance
    @next_step="next_step_insurance"
    @Previous_step="Previous_step_insurance"
    ref="insurance"
  ></Insurance>
  <InputItem
    @next_step="next_step_inputItem"
    @Previous_step="Previous_step_inputItem"
    ref="inputItem"
  ></InputItem>
  <ServiceFee
    @success="getTableData"
    @Previous_step="Previous_step_serviceFee"
    ref="serviceFee"
  ></ServiceFee>
  <ModuleConfig
    @success="getTableData"
    ref="moduleConfig"
  ></ModuleConfig>
  <SelectUser
    @success="getTableData"
    ref="selectUser"
  ></SelectUser>
  <ConfigureApp
    @success="getTableData"
    ref="configureApp"
  ></ConfigureApp>
</div>
</template>

<script>
import Add from "./LineManagement_add";
import Edit from "./LineManagement_edit";
import Details from "./LineManagement_details";
import Timely from "./LineManagement_timely";
import Insurance from "./LineManagement_insurance";
import InputItem from "./LineManagement_inputItem";
import ServiceFee from "./LineManagement_serviceFee";
import ModuleConfig from "./LineManagement_moduleConfig";
import SelectUser from "./LineManagement_selectUser";
import ConfigureApp from "./LineManagement_configureApp";
export default {
  components: {
    Add,
    Edit,
    Details,
    Timely,
    Insurance,
    InputItem,
    ServiceFee,
    ModuleConfig,
    SelectUser,
    ConfigureApp,
  },
  data(){
    return{
      filterItemList:[
        // input输入框
        { label:this.$t('LineManagementLang.Line_name'),width:200, filterKey: 'name', filterType: 'SearchInput', placeholderStr: null },
      ],
      filterData:{
        page: "",
        limit: "30",
        order: "",

        name: "",
      },
      tableColumn: [
        {
          label: "",
          prop: "table_code",
          width:40,
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Bill_review'),
          prop: "examine_type",
          width: 120,
          order:"",
          templateType:'SwitchBtn_examine_type'
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Is_enabled'),
          prop: "status",
          width: 100,
          order:"",
          templateType:'SwitchBtn_status'
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Line_name'),
          prop: "name_current",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Business_type'),
          prop: "type_name",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Origin'),
          prop: "start_local_names",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.destination'),
          prop: "target_local_names",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Delivery_method'),
          prop: "dispatch_type_names",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Pickup_method'),
          prop: "pickup_type_name",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.payment_method'),
          prop: "pay_type_name",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.Is_insurance_available'),
          prop: "is_insure_name",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.lifting_weight'),
          prop: "start_weight",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.extension_weight'),
          prop: "renew_weight",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.lifting_volume'),
          prop: "start_volume",
          width: 120,
          order:"",
        },
        {
          checked: true,
          label: this.$t('LineManagementLang.extension_volume'),
          prop: "renew_volume",
          width: 120,
          order:"",
        },
        
      ],
      tableData: [],

      pageinfo: {
        page: 1,
        page_all: 1,
        limit: 30,
        number_all: 0,
      },
      sendDataObj:{},
    }
  },
  computed: {
      tabsId() {
          return this.$store.state.tabsId;
      }
  },
  mounted(){
    this.sendDataObj={}
    this.getHeaderList()
    this.getTableData()
  },
  methods:{
    //查询
    search(){
      this.getTableData()
    },
    //清空
    clear(){
      this.filterData.name= "",
      this.getTableData()
    },
    // 获取表头组
    getHeaderList(){
      this.$get("get_th",{menu_id:this.tabsId}).then((res) => {
        if(!!res.data.th_json){
          this.tableColumn=JSON.parse(res.data.th_json)
        }
      });
    },
    //保存表头表头组
    keepHeaderList(){
        let params = new FormData();
        params.append("menu_id", this.tabsId);
        params.append("th_json", JSON.stringify(this.tableColumn));
        this.$postForm("save_th", params).then((res) => {
          
        });
    },
    // 点击排序
    setOrder(data){
      this.filterData.order=data
      this.getTableData()
    },
    // 更改分页
    SetPagination(data){
      this.filterData.page=data.page
      this.filterData.limit=data.limit
      this.pageinfo.page=data.page
      this.pageinfo.limit=data.limit
      this.getTableData()
    },
   cellDblclick(obj){
      let row=obj.row
      this.$refs.details.init(row);
    },
    pushButton(route) {
       if (route == "add") {
        this.$refs.add.init();
      } else if (route == "edit") {
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.edit.init(this.sendDataObj);
        }
      } else if (route == "del") {
        if (JSON.stringify(this.sendDataObj) == "{}") {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          let params = new FormData();
            params.append("id", this.sendDataObj.id);
            params.append("status", 1);
          this.$postForm('lineStatus',params).then((res) => {
            if(res.success){
              this.$message.success(res.msg);
            }
            this.getTableData()
          })
        }
      } else if (route == "Timely") {//时效配置
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.timely.init(this.sendDataObj);
        }
      }
       else if (route == "Insurance") {//保险配置
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.insurance.init(this.sendDataObj);
        }
      }
       else if (route == "InputItem") {//输入项配置
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.inputItem.init(this.sendDataObj);
        }
      }
       else if (route == "ServiceFee") {//服务费配置
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.serviceFee.init(this.sendDataObj);
        }
      }
        else if (route == "moduleConfig") {//模块权限
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.moduleConfig.init(this.sendDataObj);
        }
      }
        else if (route == "selectUser") {//产品控制
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.selectUser.init(this.sendDataObj);
        }
      }
        else if (route == "configureApp") {//配置APP
        if (JSON.stringify(this.sendDataObj) == "{}" || this.sendDataObj == null) {
         this.$message.warning(this.$t('common.message_warn_text'));
        } else {
          this.$refs.configureApp.init(this.sendDataObj);
        }
      }
    
    },
    //添加功能点击下一步后的操作
    next_step_add(data){
      this.sendDataObj=data
      this.$refs.timely.init(this.sendDataObj);
      this.getTableData()
    },
    //修改功能点击下一步后的操作
    next_step_edit(){
      this.$refs.timely.init(this.sendDataObj);
      this.getTableData()
    },
    //详情功能点击下一步后的操作
    next_step_details(){
      this.$refs.timely.init(this.sendDataObj,'details');
    },
    //时效配置功能点击下一步后的操作
    next_step_timely(name){
      if(name==='details'){
        this.$refs.insurance.init(this.sendDataObj,'details');
      }else{
        this.$refs.insurance.init(this.sendDataObj);
      }
    },
    //时效配置功能点击上一步后的操作
    Previous_step_timely(name){
      if(name==='details'){
        this.$refs.details.init(this.sendDataObj);
      }else{
        this.$refs.edit.init(this.sendDataObj);
      }
    },
     //保险配置功能点击下一步后的操作
    next_step_insurance(name){
      if(name==='details'){
        this.$refs.inputItem.init(this.sendDataObj,'details');
      }else{
        this.$refs.inputItem.init(this.sendDataObj);
      }
    },
    //保险配置功能点击上一步后的操作
    Previous_step_insurance(name){
      if(name==='details'){
        this.$refs.timely.init(this.sendDataObj,'details');
      }else{
        this.$refs.timely.init(this.sendDataObj);
      }
    },
    //输入项配置功能点击下一步后的操作
    next_step_inputItem(name){
      if(name==='details'){
        this.$refs.serviceFee.init(this.sendDataObj,'details');
      }else{
        this.$refs.serviceFee.init(this.sendDataObj);
      }
    },
    //输入项配置功能点击上一步后的操作
    Previous_step_inputItem(name){
      if(name==='details'){
        this.$refs.insurance.init(this.sendDataObj,'details');
      }else{
        this.$refs.insurance.init(this.sendDataObj);
      }
    },
    //服务费配置功能点击上一步后的操作
    Previous_step_serviceFee(name){
      if(name==='details'){
        this.$refs.inputItem.init(this.sendDataObj,'details');
      }else{
        this.$refs.inputItem.init(this.sendDataObj);
      }
    },
  
    switchChange_examine_type(data){
        let params = new FormData();
          params.append("id", data.id);
          params.append("examine_type", data.examine_type);
        this.$postForm('editLine',params).then((res) => {
          if(res.success){
            this.$message.success(res.msg);
          }
          this.getTableData()
        })
    },
    switchChange_status(data){
        let params = new FormData();
          params.append("id", data.id);
          params.append("status", data.status);
        this.$postForm('lineStatus',params).then((res) => {
          if(res.success){
            this.$message.success(res.msg);
          }
          this.getTableData()
        })
    },
    // 获取表格数据
    getTableData(){
      this.$get("lineList", this.filterData).then((res) => {
        this.tableData = res.data;
        this.pageinfo = res.pageinfo;
        this.pageinfo.limit=Number(this.pageinfo.limit)
        // this.sendDataObj={}
        let arr=this.tableData.filter(item=>{return item.lid==this.sendDataObj.lid})
        if(arr.length>0){
          this.$refs.LineManagement.$refs.tableRef.setCurrentRow(arr[0]);
        }
      });
    },
    setCurrent(data){
      this.sendDataObj=data
    },
  }
}
</script>
<style scoped lang="less">
.tableBox {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
</style>